package com.lu.comtroller;


import com.lu.pojo.User;
import com.lu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController

public class UserComtroller {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private UserService userService;

    @RequestMapping("/findall")
    public List<User> findAll(){
        System.out.println("来了来了");
        return userService.findall();
    }


    @RequestMapping("/find/{id}")
    public User findById(@PathVariable(value = "id") Integer id){
        User user = (User)redisTemplate.boundValueOps(id).get();
        if (user==null){
            System.out.println("这是数据库");
            user=userService.findById(id);
            redisTemplate.boundValueOps(id).set(user);
        } else {
            System.out.println("我没有走数据库哦!");
        }
        return user;
    }
}
